package cn.wolfcode.p2p.website.util;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

/**
 * 配置拦截器
 * 
 * @author wolfcode
 *
 */
@Component
public class MyWebMvcConfigurerAdapter extends WebMvcConfigurerAdapter {

	@Value("${app.imgfolder}")
	private String imgFolder;

	@Autowired
	private LoginCheckInterceptor loginCheckInterceptor;

	/**
	 * 添加拦截器
	 */
	@Override
	public void addInterceptors(InterceptorRegistry registry) {
		/**
		 * 
		 * <mvc:interceptor> <mvc:mapping path="/**" /> <bean ref=
		 * "loginCheckInterceptor" /> </mvc:interceptor>
		 */
		registry.addInterceptor(loginCheckInterceptor).addPathPatterns("/**");
		super.addInterceptors(registry);
	}

	/**
	 * 添加资源映射
	 */
	@Override
	public void addResourceHandlers(ResourceHandlerRegistry registry) {
		registry.addResourceHandler("/upload/**").addResourceLocations("file:/"+imgFolder);
		super.addResourceHandlers(registry);
	}

}
